
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

  <head>
    <base href="<%=basePath%>" />
    
   <script type="text/javascript" src="js/ajax.js"></script>
		<script type="text/javascript" src="js/jigou.js"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  
  </head>
  
  <body>
<c:if test="${!empty message}">
  	<script type="text/javascript">
  		var msg="${message}";
  		alert(msg);
  	</script>
  	<c:remove var="message"/>
  </c:if>
 <form enctype="multipart/form-data"  method="post" action="<c:url value='/admin.do?method=addKehu'/>" name="f1" onSubmit="return check_form(f1)">
<div class="biaoti" style="clear:both">小区名称/项目名称：<input type="text" style="width:320px; height:20px;" value="" name="title" id="title"/></div><br/>
户型：<input type="text" style="width:200px; height:20px;"  name="huxing" id="huxing"/></div><br/>
面积：<input type="text" style="width:200px; height:20px;"  name="mianji" id="mianji"/></div><br/>
工程地址：<input type="text" style="width:320px; height:20px;"  name="address" id="address"/></div><br/>   
业主姓名：<input type="text" style="width:200px; height:20px;"  name="nickname" id="nickname"/></div><br/>
业主电话：<input type="text" style="width:200px; height:20px;"  name="tel" id="tel"/></div><br/>
合同编号：<input type="text" style="width:200px; height:20px;"  name="hetong" id="hetong"/></div><br/>
登陆用户名：<input type="text" style="width:200px; height:20px;"  name="username"   onblur="testusername('<%=request.getContextPath()%>')" /><div id="username1"></div></div><br/>

   
     
       <input type="submit" name="yulan" class="subtn" value="添加"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <input type="reset" name="tijiao" class="subtn" value="重置"  />
       </div>
  </form>   
  </body>
</html>
<script language="javascript">
   if (window.ActiveXObject && !window.XMLHttpRequest) {
       window.XMLHttpRequest=function() {
       return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
    };
   }//取得XMLHttpRequest对象

function testusername(path){

//path是取得系统路径
                 var username1=document.getElementById("username1");
                //  var username=document.getElementById("username");
                var username= document.forms.f1.username.value;
       var req=new XMLHttpRequest();
       if (req) {
           req.onreadystatechange=function() {
            if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成
                  if(req.responseText==0){
                  username1.style.color='red';
                 username1.innerHTML='用户名不能为空';
                  }else if(req.responseText==1){
                 username1.style.color='red';
                    username1.innerHTML='用户名长度不能小于4位';
                        }else if(req.responseText==2){
                 username1.style.color='green';
                    username1.innerHTML='该用户名可以使用';
                        }else if(req.responseText==3){
                 username1.style.color='red';
                    username1.innerHTML='该用户名已经存在';
                        }else{
                      username1.style.color='red';
                      username1.innerHTML='该用户名含有非法字符！';
                      }
                  }
          }
                         req.open('POST', path+'/admin.do?method=getCompanyByNameAJAX');//struts


                           req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                           req.send("username="+username);//发送参数如果有参数req.send("username="+user_name);用request取得
       }
}

function check_form(f1){

 var username1 = document.getElementById("username1").innerHTML;
  if(f1.title.value.length==0){
	  alert("小区名称不能为空！"); 
	  return false;
  }else  if(f1.nickname.value==""){
	  alert("业主姓名不能为空！"); 
	  return false;
  }else if(f1.username.value==""){
	
		   document.getElementById("username1").style.color='red';
		   document.getElementById("username1").innerHTML="请输入用户名";
		  return false;
		}else if(username1=="用户名长度不能小于4位"){
		 
		  return false;
		}else if(username1=="该用户名已经存在"){
		 
		  return false;
		}else if(username1=="该用户名含有非法字符！"){
		 
		  return false;
		}else if(username1=="用户名不能为空"){
		 
		  return false;
		}
  
  return true;
}

</script>